using System;
using System.Collections;

namespace Pitoshka.Tools.Helpers.TemplateParser
{
    /// <summary>
    /// Abstract class for Modificators
    /// </summary>
    public abstract class Modificator
    {
        protected Hashtable _parameters = new Hashtable();

        public Hashtable Parameters
        { 
            get { return _parameters; }
        }

        public abstract void Apply(ref string Value, params string[] Parameters);
    }

    class NL2BR : Modificator
    {
        public override void Apply(ref string Value, params string[] Parameters)
        {
			Value = Value.ToString().Replace("\n", "<br>");
        }
    }

    class HTMLENCODE : Modificator
    {
        public override void Apply(ref string Value, params string[] Parameters)
        {
            Value = Value.ToString().Replace("&", "&amp;");
			Value = Value.ToString().Replace("<", "&lt;");
			Value = Value.ToString().Replace(">", "&gt;");
        }
    }

    class UPPER : Modificator
    {
        public override void Apply(ref string Value, params string[] Parameters)
        {
			Value = Value.ToString().ToUpper();
        }
    }

    class LOWER : Modificator
    {
        public override void Apply(ref string Value, params string[] Parameters)
        {
			Value = Value.ToString().ToLower();
        }
    }

    class TRIM : Modificator
    {
        public override void Apply(ref string Value, params string[] Parameters)
        {
			Value = Value.ToString().Trim();
        }
    }

    class TRIMEND : Modificator
    {
        public override void Apply(ref string Value, params string[] Parameters)
        {
			Value = Value.ToString().TrimEnd();
        }
    }

    class TRIMSTART : Modificator
    {
        public override void Apply(ref string Value, params string[] Parameters)
        {
			Value = Value.ToString().TrimStart();
        }
    }
	class TOSTRING : Modificator
	{
		public override void Apply(ref string Value, params string[] Parameters)
		{
			if (Value is DateTime)
				Value = Value.ToString().ToString();
		}
	}

    class DEFAULT : Modificator
    {
        public override void Apply(ref string Value, params string[] Parameters)
        {
			if (Value == null || Value.ToString().Trim() == string.Empty)
                Value = Parameters[0];
        }
    }
}